package de.baumann.browser.fragments.gg

import android.view.View
import de.baumann.browser.R
import de.baumann.browser.adapter.MiningRecordAdapter
import de.baumann.browser.api.net.vo.gg.Morgage
import de.baumann.browser.base.BaseOdinFragment
import de.baumann.browser.db.ETHWallet
import de.baumann.browser.iview.gg.IMiningRecordsView
import de.baumann.browser.present.gg.MiningRecordsPresenter
import kotlinx.android.synthetic.main.fragment_mining_records.*

class MiningRecordsFragment : BaseOdinFragment<IMiningRecordsView, MiningRecordsPresenter>(), IMiningRecordsView {

    companion object {
        val instance: MiningRecordsFragment by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            MiningRecordsFragment()
        }
    }

    private lateinit var miningRecordAdapter: MiningRecordAdapter


    override fun getLayout(): Int {
        return R.layout.fragment_mining_records
    }

    override fun initView(view: View) {
        miningRecordAdapter = MiningRecordAdapter()
        rvMiningRecord.adapter = miningRecordAdapter
    }

    override fun initData() {
        getPresenter().a02(getWallet().address)
    }

    override fun createPresenter(): MiningRecordsPresenter? {
        return MiningRecordsPresenter()
    }

    override fun createView(): IMiningRecordsView? {
        return this
    }

    override fun setList(list: List<Morgage>) {
        miningRecordAdapter.setNewData(list)
    }

    fun getWallet():ETHWallet{
        return arguments?.getSerializable("wallet") as ETHWallet
    }

}